// service-detail.ts
const app = getApp<IAppOption>()

interface ServiceDetail {
  id: number;
  name: string;
  price: number;
  duration: string;
  image: string;
  description: string;
  features: string[];
}

Component({
  data: {
    serviceId: 0,
    service: null as ServiceDetail | null
  },

  methods: {
    onLoad(options: any) {
      const serviceId = parseInt(options.id || '0')
      this.setData({ serviceId })
      this.loadServiceDetail()
    },

    handlerGobackClick() {
      wx.navigateBack({
        delta: 1
      })
    },

    loadServiceDetail() {
      const { serviceId } = this.data
      
      wx.request({
        url: `${app.globalData.apiConfig.baseUrl}/project/query`,
        method: 'POST',
        data: {
          id: serviceId
        },
        success: (res: any) => {
          const resp = res.data
          if (resp.code === 200 && resp.data) {
            this.setData({
              service: resp.data
            })
          } else {
            console.error('获取服务详情失败:', res)
          }
        },
        fail: (err: any) => {
          console.error('请求服务详情接口失败:', err)
        }
      })
    },

    goToBooking() {
      wx.navigateTo({
        url: `/pages/booking/booking?id=${this.data.serviceId}`
      })
    }
  }
})